package com.dd.mall.protal.web.controller;

import com.dd.common.entity.cms.SubjectVo;
import com.dd.common.entity.pms.ProductCategoryVo;
import com.dd.common.entity.view.CommonPage;
import com.dd.common.entity.view.CommonResult;
import com.dd.common.error.ApiError;
import com.dd.mall.protal.web.service.IndexService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "首页内容查询",description = "主要包含首页中商品分类接口")
@RestController
public class IndexController {

    @Autowired
    private IndexService indexService;

    @ApiOperation(value="查询商品分类",notes = "根据父分类id获取子分类，顶级父类id为0",httpMethod = "GET")
    @GetMapping("/index/{parentId}")
    @ApiImplicitParam(value = "父分类id",name = "parentId",defaultValue = "0",required = true,paramType = "path")
    public CommonResult<List<ProductCategoryVo>> index(@PathVariable(value = "parentId",required = false)int parentId){
//        if (StringUtils.isBlank(parentId)){
//            parentId = "0";
//        }
        List<ProductCategoryVo> productCategoryVoList = indexService.queryProductCategoryByParentId(parentId);

        CommonResult m = CommonResult.success(productCategoryVoList);
        return m;
    }



    @ApiOperation(value="根据分类获取专题",notes = "根据分类分页查询专题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类id",name = "cateId",defaultValue = "0",required = true,paramType = "query"),
            @ApiImplicitParam(value = "每页显示行数",name = "pageSize",defaultValue = "5",required = true,paramType = "query"),
            @ApiImplicitParam(value = "页码",name = "pageNum",defaultValue = "1",required = true,paramType = "query")
    })
    @GetMapping(value = "/subjectList")
    public CommonResult<CommonPage<List<SubjectVo>>> getSubjectList(@RequestParam(required = false) Long cateId,
                                                        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        CommonPage<List<SubjectVo>> subjectList = indexService.querySubjectForPage(cateId,pageSize,pageNum);
        return CommonResult.success(subjectList);
    }


}
